﻿@using Mix.Cms.Lib;
@using Mix.Cms.Lib.Services;
@model Mix.Cms.Lib.Interfaces.IMvcViewModel
@{
    var assetFolder = MixCmsHelper.GetAssetFolder(ViewBag.culture);
    string master = MixService.GetConfig<string>(MixAppSettingKeywords.ThemeName, ViewBag.culture);
    string templateFolder = MixCmsHelper.GetTemplateFolder(ViewBag.culture);
    string layout = Model.Layout ?? "Masters/_Layout.cshtml";
    var masterTemplate = await MixCmsHelper.GetTemplateByPath(master, layout);
    string keyword = ViewData["Keyword"] as string;
    Layout = $"{templateFolder}/{layout}";
}
<input type="hidden" id="view-type" value="Alias" />
<input type="hidden" id="view-id" value="@Model.Id" />

@if (!string.IsNullOrEmpty(Model.TemplatePath))
{

    try
    {
        @await Html.PartialAsync(Model.TemplatePath, Model)
    }
    catch (System.InvalidOperationException invalidOperationException)
    {
        <p class="danger text-center has-error">Unable load template @Model.TemplatePath with Exception detail below:</p>
        <code>
            @invalidOperationException
        </code>
    }
    catch (Exception ex)
    {
        <code>
            @ex
        </code>
    }
}
else
{
    <section class="container">
        <h1>@(MixService.Translate<string>("Please choose template", ViewBag.culture))</h1>
    </section>
}
@{
    string url = ViewData["OgUrl"] != null ? (string)ViewData["OgUrl"] : Model.DetailsUrl;
    var domain = url.IndexOf("http") == -1 ? $"{Context.Request.Scheme}://{Context.Request.Host}" : string.Empty;
    string title = ViewData["OgTitle"] != null ? (string)ViewData["OgTitle"] : Model.SeoTitle;
    string desc = ViewData["OgDescription"] != null ? (string)ViewData["OgDescription"] : Model.SeoDescription;
    string image = ViewData["OgImage"] != null ? (string)ViewData["OgImage"] : Model.ThumbnailUrl;
}
@section Seo{
    <title>@Model.SeoTitle</title>
    <meta property="og:type" content="post" />
    <!--points to the regular HTML version of the AMP HTML document or to itself if no such HTML version exists-->
    <link rel="canonical" href="@domain@url" />
    <meta property="og:url" content=@domain"@url" />
    <meta property="og:title" content="@title" />
    <meta property="og:description" content="@desc" />
    <meta property="og:image" content="@domain@image" />
    <meta name="title" content="@title" />
    <meta name="description" content="@desc" />
    <meta name="keywords" content="@desc" />
}
@section Styles{
    @Html.Raw(masterTemplate?.Styles)
    @Html.Raw(Model.View?.Styles)
}
@section Scripts{
    @Html.Raw(masterTemplate?.Scripts)
    @Html.Raw(Model.View?.Scripts)
}